using System;
using System.ComponentModel;
using System.Windows.Forms;
using Microsoft.WindowsCE.Forms;

namespace Christian.Helle.PocketNews.PocketPC
{
    public class FormEx : Form
    {
        private InputPanel sip;

        public FormEx()
        {
            Text = "Pocket News";
            Closing += FormEx_Closing;
        }

        void FormEx_Closing(object sender, CancelEventArgs e)
        {
            if (sip != null)
            {
                if (sip.Enabled)
                {
                    sip.Enabled = false;
                }
                sip.EnabledChanged -= SIP_EnabledChanged;
                sip.Dispose();
                sip = null;
            }
        }

        public void EnableSmartSIP()
        {
            sip = new InputPanel();
            sip.EnabledChanged += SIP_EnabledChanged;
        }

        private void SIP_EnabledChanged(object sender, EventArgs e)
        {
            if (sip.Enabled)
            {
                Height += sip.Bounds.Height;
                foreach (Control ctrl in Controls)
                {
                    ctrl.Top -= sip.Bounds.Height;
                }
            }
            else
            {
                Height -= sip.Bounds.Height;
                foreach (Control ctrl in Controls)
                {
                    ctrl.Top += sip.Bounds.Height;
                }
            }
        }
    }
}